package org.mozhu.zufang.admin.web.controller;

import org.mozhu.mboot.core.web.controller.Permissions;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HomeController {

    @RequestMapping("/echo")
    @ResponseBody
    public String echo() {
        return "hello world" + System.currentTimeMillis();
    }

    @RequestMapping({"", "/home"})
    public String home() {
        return "home";
    }

    @RequestMapping("/has/role/user")
    @ResponseBody
    @PreAuthorize("hasRole('USER')")
    public String hasRoleUser() {
        return "has role user" + System.currentTimeMillis();
    }

    @RequestMapping("/has/role/admin")
    @ResponseBody
    @PreAuthorize("hasRole('ADMIN')")
    public String hasRoleAdmin() {
        return "has role admin" + System.currentTimeMillis();
    }

    @RequestMapping("/has/authority/user")
    @ResponseBody
    @PreAuthorize("hasAuthority('system:user:create')")
    public String hasAuthority() {
        return "has authority system:user:add" + System.currentTimeMillis();
    }

    @RequestMapping("/has/authority/user2")
    @ResponseBody
    public String hasAuthority2() {
        Permissions.newPermissionList("system:user").assertHasPermission("create");
        return "has authority system:user:add" + System.currentTimeMillis();
    }
}
